package com.zxw.hystrix;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;

/**
 * @author zxw
 * @date 2021-11-18 21:43
 */
@Component
@Slf4j
public class TestCommand extends HystrixCommand<User> {
    private String userId;
    @Autowired
    @LoadBalanced
    private RestTemplate restTemplate;


//    @Autowired
//    private StorageFeignClient storageFeignClient;
//    @Autowired
//    private OrderFeignClient orderFeignClient;

    protected TestCommand() {
        super(HystrixCommandGroupKey.Factory.asKey("GetProductInfoCommandGroup"));
    }

    @Override
    protected User run() throws Exception {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        String urlString = "http://localhost:8084/storage-tbl/deduct?commodityCode=C100000&count=30";
        String s = restTemplate.postForObject(urlString, "", String.class);
//        HttpUtil.get(urlString);
//        stopWatch.stop();
//        log.info("{}",stopWatch.getTotalTimeSeconds());
        stopWatch.stop();
        log.info("{}",stopWatch.getTotalTimeSeconds());
//        storageFeignClient.deduct("C100000", 30);
        return null;
    }

}
